//
//  LGDiseaseOverviewHeaderView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/10/16.
//  病情概览 - 区头

#import "LGDiseaseOverviewHeaderView.h"

@interface LGDiseaseOverviewHeaderView()

/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIButton *titleBtn;
/**   */
@property (nonatomic , strong)UIView *lineView;


@end

@implementation LGDiseaseOverviewHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setTitle:(NSString *)title{
    _title = title;
    [self.titleBtn setTitle:title forState:UIControlStateNormal];
    [self.titleBtn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"病情概览-%@",title]] forState:UIControlStateNormal];
}

-(void)setSubTitle:(NSString *)subTitle{
    _subTitle = subTitle;
    self.subtitleLabel.text = subTitle;
    self.tipView.hidden = (subTitle.length>0 && self.showTip == YES)?NO:YES;
}

-(void)setShowTip:(BOOL)showTip{
    _showTip = showTip;
    self.actionBtn.hidden = !showTip;
    self.subtitleLabel.hidden = !showTip;
    self.tipView.hidden = !showTip;
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor clearColor];
    [self addSubview:self.baseView];
    [self.baseView addSubview:self.titleBtn];
    [self.baseView addSubview:self.subtitleLabel];
    [self.baseView addSubview:self.tipView];
    [self.baseView addSubview:self.lineView];
    [self.baseView addSubview:self.actionBtn];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self).offset(viewPix(8));
        make.left.equalTo(self).offset(viewPix(16));
        make.right.equalTo(self).offset(-viewPix(16));
        make.bottom.equalTo(self).offset(viewPix(16));
    }];
    [self.titleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.baseView).offset(viewPix(13));
        make.left.equalTo(self.baseView).offset(viewPix(16));
        make.width.equalTo(@(viewPix(150)));
        make.height.equalTo(@(viewPix(24)));
    }];
    [self.subtitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.tipView.mas_left).offset(-viewPix(2));
        make.centerY.equalTo(self.titleBtn);
    }];
    [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.equalTo(self.titleBtn);
        make.width.height.equalTo(@(viewPix(12)));
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleBtn);
        make.right.equalTo(self.tipView);
        make.bottom.equalTo(self);
        make.height.equalTo(@(0.5));
    }];
    [self.actionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.equalTo(self.baseView);
    }];
}
    
-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:10];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UIButton *)titleBtn{
    if(!_titleBtn){
        _titleBtn = [UIButton buttonWithTitle:@"" titleFont:LGFontWeight(16, UIFontWeightMedium) textColor:@"#333333" imageName:@""];
        _titleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _titleBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 6, 0, 0);
        _titleBtn.userInteractionEnabled = NO;
    }
    return _titleBtn;
}

-(UILabel *)subtitleLabel{
    if(!_subtitleLabel){
        _subtitleLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _subtitleLabel;
}

-(UIImageView *)tipView{
    if(!_tipView){
        _tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip12"]];
    }
    return _tipView;
}


-(UIButton *)actionBtn{
    if(!_actionBtn){
        _actionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    }
    return _actionBtn;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor colorWithString:@"#E8E8E8"];
    }
    return _lineView;
}

@end
